<?php
define('FPDF_FONTPATH','font/');
require_once('fpdf.php');
require_once('gisp_admincon.php');
require_once('qrcode.class.php');
require_once("Connections/coneccionRatania.php");
require_once("Connections/funciones_pg.php");
//include_once('rotation.php');



	
	
class PDF extends FPDF{

var $angle=0;
var $javascript;
var $n_js;

	function IncludeJS($script) {
		$this->javascript=$script;
	}

	function _putjavascript() {
		$this->_newobj();
		$this->n_js=$this->n;
		$this->_out('<<');
		$this->_out('/Names [(EmbeddedJS) '.($this->n+1).' 0 R]');
		$this->_out('>>');
		$this->_out('endobj');
		$this->_newobj();
		$this->_out('<<');
		$this->_out('/S /JavaScript');
		$this->_out('/JS '.$this->_textstring($this->javascript));
		$this->_out('>>');
		$this->_out('endobj');
	}


function AutoPrint($dialog=false)
{
	//Open the print dialog or start printing immediately on the standard printer
	$param=($dialog ? 'true' : 'false');
	$script="print($param);";
	$this->IncludeJS($script);
}

function AutoPrintToPrinter($server, $printer, $dialog=false)
{
	//Print on a shared printer (requires at least Acrobat 6)
	$script = "var pp = getPrintParams();";
	if($dialog)
		$script .= "pp.interactive = pp.constants.interactionLevel.full;";
	else
		$script .= "pp.interactive = pp.constants.interactionLevel.automatic;";
	$script .= "pp.printerName = '\\\\\\\\".$server."\\\\".$printer."';";
	$script .= "print(pp);";
	$this->IncludeJS($script);
}


	function _putresources() {
		parent::_putresources();
		if (!empty($this->javascript)) {
			$this->_putjavascript();
		}
	}

	function _putcatalog() {
		parent::_putcatalog();
		if (!empty($this->javascript)) {
			$this->_out('/Names <</JavaScript '.($this->n_js).' 0 R>>');
		}
	}
	

function Rotate($angle,$x=-1,$y=-1)
{
	if($x==-1)
		$x=$this->x;
	if($y==-1)
		$y=$this->y;
	if($this->angle!=0)
		$this->_out('Q');
	$this->angle=$angle;
	if($angle!=0)
	{
		$angle*=M_PI/180;
		$c=cos($angle);
		$s=sin($angle);
		$cx=$x*$this->k;
		$cy=($this->h-$y)*$this->k;
		$this->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
	}
}

function _endpage()
{
	if($this->angle!=0)
	{
		$this->angle=0;
		$this->_out('Q');
	}
	parent::_endpage();
}

function RotatedText($x,$y,$txt,$angle)
{
    //Text rotated around its origin
    $this->Rotate($angle,$x,$y);
    $this->Text($x,$y,$txt);
    $this->Rotate(0);
}

function RoundedRect($x, $y, $w, $h, $r, $style = '')
    {
        $k = $this->k;
        $hp = $this->h;
        if($style=='F')
            $op='f';
        elseif($style=='FD' || $style=='DF')
            $op='B';
        else
            $op='S';
        $MyArc = 4/3 * (sqrt(2) - 1);
        $this->_out(sprintf('%.2F %.2F m',($x+$r)*$k,($hp-$y)*$k ));
        $xc = $x+$w-$r ;
        $yc = $y+$r;
        $this->_out(sprintf('%.2F %.2F l', $xc*$k,($hp-$y)*$k ));

        $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
        $xc = $x+$w-$r ;
        $yc = $y+$h-$r;
        $this->_out(sprintf('%.2F %.2F l',($x+$w)*$k,($hp-$yc)*$k));
        $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
        $xc = $x+$r ;
        $yc = $y+$h-$r;
        $this->_out(sprintf('%.2F %.2F l',$xc*$k,($hp-($y+$h))*$k));
        $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
        $xc = $x+$r ;
        $yc = $y+$r;
        $this->_out(sprintf('%.2F %.2F l',($x)*$k,($hp-$yc)*$k ));
        $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
        $this->_out($op);
    }

    function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
    {
        $h = $this->h;
        $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $x1*$this->k, ($h-$y1)*$this->k,
            $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
    }
	
	function Header(){
		//datos SQL
		global $login;
		global $centro_costo;
		global $nom_oficina;
		global $cod_actproy;
		global $des_actproy;
		global $cod_nemonico;
		global $des_nemonico;
		global $title;
		global $nro_nec;
		global $ano_eje;
		global $fch_nec;
		global $tipo_bien;
		global $reqs_anuales;			
		global $topIni;
		global $marIni;
		global $wcel;
		global $empresaM;
		global $distrito;
		global $departamento;
		global $provincia;
		global $logoCabIzq;
		global $logoSupP1;
		global $logoSupP2;
		global $logoSupP3;
		global $logoSupP4;
		global $marcaAguaP1;
		global $marcaAguaL1;
		global $marcaAguaL2;
		global $marcaAguaL3;
		global $marcaAguaL4;global $marcaAguaP2;
		global $marcaAguaP3;
		global $marcaAguaP4;
		global $marcaDeAgua;
		global $repositorioFirmas;
		global $RUC;
		global $numero_recibo;
		global $codigoContrib;
		global $nombreContrib;
		global $nroDoc;
		global $direccionContrib;
		global $cajero;
		global $fechaEmision;
		global $fechaImpresion;
		global $fechaProyectado1;
                global $fechaIni;
                global $fechaFin;
		global $err;
		global $fechaRecargos;
		global $usuario;
		global $colCab;
		global $colSubCab;
                global $subTipoReporte;
                global $tipoReporte;
		
		
		
		$lw = $marIni;
		$ln = $topIni;
		$ls = 3;
		$lh = 0;
		//MArca de Agua
		$this->Image('../img/marca/escudomarcaagua4.png',$marcaAguaL1-20,$marcaAguaL2,$marcaAguaL3+50,$marcaAguaL4+50,'PNG');
		
		//Logo
		$this->SetFont('arial','B',9);
		//$this->SetFillColor(206,232,212); //verde agua
		$this->SetFillColor(188,217,190); //verde agua
		$this->SetXY($lw-10,$lh);
		$this->Cell(220,8,"",0,1,'L',true);
		$this->SetFillColor(243);
		$this->SetFont('arial','B',9);
		$this->SetXY($lw-10,$lh);
		$this->MultiCell(50,8,'Calle 9 de Junio Nro 100',1,'C');
		$this->SetXY($lw+40,$lh);
		$this->MultiCell(50,8,'Puente Piedra - Lima - Peru',1,'C');
		$this->SetXY($lw+90,$lh);
		$this->MultiCell(50,8,'www.munipuentepiedra.gob.pe',1,'C');
		$this->SetXY($lw+140,$lh);
		$this->MultiCell(60,8,'Telefono 219 6200 - 219 6201',1,'C');
		//$this->RoundedRect(-10, 0, 220, 8, 1,'S');
		$this->Image('../img/marca/munipuentepiedra.png',$lw,$ln,62,18,'PNG');
		
		//$this->SetFillColor(145,185,154); //verde agua
		$this->SetFillColor(255);
		$lh = $lh+9;
		$this->SetXY($lw+70,$lh);
		$this->Cell(160,12,"",0,1,'L',true);
		$this->SetFont('arial','B',14);
		$this->SetXY($lw+60,$lh);
		$this->MultiCell(140,10,'SUB GERENCIA DE TESORERIA',0,'C');
		
		
		//definimos  ancho y color de rectangulo
		$lh = $lh+20;
		$this->SetLineWidth(0.3);
		$this->SetFillColor(255);
		$this->RoundedRect($lw-5, $lh, 110, 27, 1, '');
		$this->SetFont('arial','B',12);
		$this->SetXY($lw,$lh+2);
		$this->MultiCell(100,5,$tipoReporte,0,'C');
		$this->SetFont('arial','B',12);
		$this->SetXY($lw+10,$lh+12);
		$this->MultiCell(80,5,$subTipoReporte,0,'C');
		
		//$qrcode = new QRcode(utf8_encode('Hola'), $err);
		//$qrcode->disableBorder();
		
		//aqui va el codigo de barras
		//$qrcode->displayHTML();
		//$this->SetXY($lw+10,$lh+12);
		//$qrcode->displayPNG(50);
		//$this->Image(,$lw,$ln,62,18,'PNG');
		
		//$this->SetXY($lw,$lh + 17 );
		$this->Image('../img/marca/barraBoucher_2dat.gif',$lw-3,$lh+12,13,13,'GIF','');
		
                
                $ls = 6;
		$this->RoundedRect($lw+110, $lh-$ls, 85, 27, 1, '');
		$this->SetFont('arial','B',10);
		$this->SetXY($lw+110,$lh-$ls);
		$this->Cell(42,8,"",1,1,'L',true);
		$this->SetXY($lw+112,$lh+2-$ls);
		$this->MultiCell(40,5,'CAJERO',0,'J');
		$this->SetXY($lw+152,$lh-$ls);
		$this->Cell(43,8,"",1,1,'L',true);
		$this->SetXY($lw+152,$lh+2-$ls);
		$this->SetFont('f25bankprinter','',14);
		$this->MultiCell(43,5,$cajero,0,'R');
		
		$this->SetFont('arial','B',10);
		$this->SetXY($lw+110,$lh+8-$ls);
		$this->Cell(42,8,"",1,1,'L',true);
		$this->SetXY($lw+112,$lh+9-$ls);
		$this->MultiCell(40,5,'Desde',0,'J');
		$this->SetXY($lw+152,$lh+8-$ls);
		$this->Cell(43,8,"",1,1,'L',true);
		$this->SetXY($lw+152,$lh+9-$ls);
		$this->SetFont('f25bankprinter','',14);
		$this->MultiCell(43,5,$fechaIni,0,'R');
                
                $this->SetFont('arial','B',10);
		$this->SetXY($lw+110,$lh+14-$ls);
		$this->Cell(42,8,"",1,1,'L',true);
		$this->SetXY($lw+112,$lh+15-$ls);
		$this->MultiCell(40,5,'Hasta',0,'J');
		$this->SetXY($lw+152,$lh+14-$ls);
		$this->Cell(43,8,"",1,1,'L',true);
		$this->SetXY($lw+152,$lh+15-$ls);
		$this->SetFont('f25bankprinter','',14);
		$this->MultiCell(43,5,$fechaFin,0,'R');
		
		
		$this->SetFont('arial','B',10);
		$this->SetXY($lw+110,$lh+20-$ls);
		$this->Cell(42,6,"",1,1,'L',true);
		$this->SetXY($lw+112,$lh+21-$ls);
		$this->MultiCell(40,4,'Usuario Imprime',0,'J');
		$this->SetXY($lw+152,$lh+20-$ls);
		$this->Cell(43,6,"",1,1,'L',true);
		$this->SetXY($lw+152,$lh+21-$ls);
		$this->SetFont('f25bankprinter','',10);
		$this->MultiCell(43,4,$usuario,0,'R');
		
		$this->SetFont('arial','B',10);
		$this->SetXY($lw+110,$lh+26-$ls);
		$this->Cell(42,7,"",1,1,'L',true);
		$this->SetXY($lw+112,$lh+27-$ls);
		$this->MultiCell(40,4,'Fecha Impresion',0,'J');
		$this->SetXY($lw+152,$lh+26-$ls);
		$this->Cell(43,7,"",1,1,'L',true);
		$this->SetXY($lw+152,$lh+27-$ls);
		$this->SetFont('f25bankprinter','',8);
		$this->MultiCell(43,4,$fechaImpresion,0,'R');
		$lh = $lh +35;
		
		$ls=-5;
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]+$colSubCab[0][1],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]+$colSubCab[0][1],3,'Partida',0,'C');
		$this->SetXY($lw+$ls+$colSubCab[0][0]+$colSubCab[0][1],$lh);
		$this->Cell($colSubCab[0][2],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls+$colSubCab[0][0]+$colSubCab[0][1],$lh+1);
		$this->MultiCell($colSubCab[0][2],3,'Rubro',0,'C');
		
		$ls = $colSubCab[0][0]+$colSubCab[0][1]+$colSubCab[0][2]-5;
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[1]+$colCab[2],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colCab[1]+$colCab[2],3,'Descripcion',0,'C');
		
			
		
		$ls = $colSubCab[0][0]+$colSubCab[0][1]+$colSubCab[0][2]+$colCab[1]+$colCab[2]-5;
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[3],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colCab[3],3,'Monto',0,'C');
		

		
	}
	
	function Footer(){
		global $marini;
		global $nro_nec;
		global $ano_eje;
		global $nombreGispAdmincon;
		//Posición: a 1,5 cm del final
		$this->SetXY($marini,-15);
		//Arial italic 8
		$this->SetFont('Arial','',10);
		//Número de página
		$this->Cell(79,5,'Municipalidad Distrital de Puente Piedra',0,0,'L',0);
		$this->SetFont('Arial','',8);
		$this->SetXY($marini,-10);
		$this->Cell(0,5,utf8_decode('Pagina N° ').$this->PageNo().' de {nb}',0,0,'R');
		$this->SetXY($marini,-10);
		$this->Cell(79,5,'GIT - Gestor Integrado Tributario',0,0,'L',0);
		
	}
	
	function WriteResumen($x,$h, $corte){
		//datos SQL
		global $Coneccion;
		global $ano_eje;
		global $nro_nec;

		//datos DOC
		global $marini;
		global $topmar;
		global $repositorioFirmas;
                global $fechaFin;
                global $fechaIni;
                global $cajero2;
                global $cajero3;
                global $ConeccionRatania;
                global $Idcajero;
                global  $nroCaja;
                global  $usuarioCaja;
                global  $nombreccajero;
                global  $sumFte09;
                global  $sumFte08;





                if($h >= 200){
			if($corte){
				$this->SetXY(15,$h + 5);
				//$this->Write(12,'corte 1');
			}else{
				$this->SetXY(15,$h + 10);
				//$this->Write(10,'corte 0');
			}
		}else{
			$this->SetXY(15,$h + 5);
			//$this->Write(12,'corte 3');
		}

		$style = array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '0', 'phase' => 10, 'color' => array(0,0,0));
		$this->Line(0, 0, 1, 0, $style);
		
                
                
		$this->SetFont('Arial','B',9);
		$this->Cell(170,4,'RESUMEN',1,1,'C',0);
		$this->SetX(15);
		$this->Cell(20,4,'RUBRO',1,0,'C',0);
		$this->Cell(110,4,  utf8_decode ('DESCRIPCIÓN'),1,0,'C',0);
		$this->Cell(40,4,'MONTO',1,1,'C',0);
		
		
                $this->SetFont('Arial','',9);
                $this->SetX(15);
                $this->Cell(20,4,'08',1,0,'L',0);
                $this->Cell(110,4,'IMPUESTOS',1,0,'L',0);
                $this->Cell(40,4,  number_format( $sumFte08,2,',',' '),1,1,'R',0);
                 $this->SetFont('Arial','',9);
                $this->SetX(15);
                $this->Cell(20,4,'09',1,0,'L',0);
                $this->Cell(110,4,'TASAS/PAGOS DIVERSOS',1,0,'L',0);
                $this->Cell(40,4,  number_format( $sumFte09,2,',',' '),1,1,'R',0);
                $this->SetFont('Arial','',9);
                $this->SetX(15);
                $this->Cell(20,4,'',1,0,'L',0);
                $this->Cell(110,4,'',1,0,'L',0);
                $this->Cell(40,4,  number_format( $sumFte09+$sumFte08,2,',',' '),1,1,'R',0);
			
			
		
		
		return $flag;
	}
	
	function CheckPageBreak($h){
		if($h >= 260){
			$this->AddPage();	
			return 1;
		}else{
			$this->SetY($h);
			return 0;
		}
		/*if($h >= 250){
			$this->AddPage('P','mm','A4');
			return true;
		}*/
	}
	
	
}


$usuario = $_GET['P_USERIMPR'];
$cajero =  $_GET['P_NROCAJA'];

$fechaIni=$_GET['P_FECHADESDE'];
$fechaFin=$_GET['P_FECHAHASTA'];
$subTipoReporte = '';
$tipoReporte = 'REPORTE DE INGRESOS POR PARTIDA PRESUPUESTAL';

$Rs_grabar = new TSPResult($ConeccionRatania,"");
$Rs_grabar->Poner_MSQL(" 
SELECT sum(t10.monto) as monto ,sum(t10.insoluto) as insoluto,
sum(t10.reajustado) as reajustado,sum(t10.mora) as mora, sum(t10.ged) as ged
,t10.cod_par,t10.cod_fte,t2.nom_sespe_clas,
tipoingreso
FROM
(    
SELECT monto,insoluto,reajustado,
mora,
ged,
tipoingreso,
descripcion,
cod_par,
cod_fte 
from 
tesoreria.fn_reporte_partida_ingreso('".$cajero."%', '".$fechaIni." 00:00:00', '".$fechaFin." 23:59:59', '1')
UNION ( SELECT 
monto,insoluto,reajustado,
mora,
ged,
tipoingreso,
descripcion,
cod_par,
cod_fte  
from  tesoreria.fn_reporte_partida_ingreso_mora('".$cajero."%', '".$fechaIni." 00:00:00', '".$fechaFin." 23:59:59', '1') )
UNION ( SELECT 
monto,insoluto,
reajustado,
mora,
ged,
tipoingreso,
descripcion,
cod_par,
cod_fte  
from  tesoreria.fn_reporte_partida_ingreso_ged('".$cajero."%', '".$fechaIni." 00:00:00', '".$fechaFin." 23:59:59', '1') )
)    
as t10
LEFT JOIN tesoreria.sespe_clasificador as t2 ON (t2.cod_par=t10.cod_par
AND t2.ano_eje='".strftime('%Y')."')
GROUP BY t10.cod_par,t10.cod_fte,t2.nom_sespe_clas,t10.tipoingreso
ORDER BY t10.cod_par ;


");
$Rs_grabar->pg_Poner_Esquema("tesoreria");

$Rs_grabar->executeMSQL();



//echo "<br><br>CONSULTA REQ UPDATE <br> ".$Rs_grabar->Escribir_Consulta();			
$row= $Rs_grabar->pg_Get_Row();



$RUC='20131366702';
$numero_recibo='860100100014';


$codigoContrib=$row['cidpers'];
$nombreContrib=$row['vrazsoc'];
$direccionContrib=$row['vdirfis'];
$fechaProyectado1=$row['fecproy']; 
//$cajero='NDIESTRO';
//$usuario='NDIESTRO';
//$fechaEmision='12-12-2013 15:56';

//echo 'HOLA '.$fechaProyectado ;
//echo 'USUARIO '.$usuario ;
if($cajero=='' or !isset($cajero) or $cajero=='undefined')
    $cajero='TODOS';

//$usuario='JTARDIO';
date_default_timezone_set('America/Lima');

if($usuario=='JTARDIO'){
	$fecha=explode('-',trim($fechaIni));
		$fecha1=$fecha['2'].'/'.$fecha['1'].'/'.$fecha['0'];  
	$fechaImpresion=$fecha1.' 17'.strftime(':%M:%S');

}else{
	$fechaImpresion=strftime('%d/%m/%Y %H:%M:%S'); 
}

//$fechaImpresion="31/07/2014 20:45:59"; 


//$fechaRecargos = '13/12/2013';
if (!in_array($err, array('L', 'M', 'Q', 'H'))) $err = 'Q';

$colCab = array('61','78','51','35','220');
$colSubCab[0] = array('10','8','18');
$colSubCab[1] = array('18','20','25');
$colSubCab[2] = array('18','8','25');

$topIni = 10;
$marIni = 10; 
$topmar = 65;
//$lw=10;

$pdf = new PDF('P','mm','A4');
$pdf->SetDisplayMode('fullpage');
//$pdf->AutoPrint();
//$pdf->AutoPrint();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);


$var1 = $pdf->GetY()+1;
//$var1 = $topmar+5;
$pdf->SetXY($lw,$lh = $var1);


	$N = 0;
	$numRows = $Rs_grabar->pg_Num_Rows();
	
	$tipoIngreso = "###";
	$codPar = "####";
	$predioContrib= "####";
	
        
        $sumTotalPartida = 0;
        $sumMoraPartida = 0;
        $sumGEDPartida = 0;
	$sumFte08 = 0;
        $sumFte09 = 0;
	while($N < $numRows){
		
		$row= $Rs_grabar->pg_Get_Row();
                $lz=0;
                $ls=-5;
                $lw=$marIni;
		//echo "TIPO INGRESO ".$row['ctiping']." - ".$tipoIngreso."<br>";
		if($codPar <> $row['cod_par'] ){
				
                    $codPar = $row['cod_par'];
                    $sumTotalPartida = 0;
			
                }
			
				$ls=-5;
				/*
                                $pdf->SetFont('arial','',8);
				$pdf->SetXY($lw+$ls,$lh+$lz);
				$pdf->MultiCell($colSubCab[0][0]+$colSubCab[0][1],4,"",0,'J');
				$pdf->SetXY($lw+$ls+$colSubCab[0][0]+$colSubCab[0][1],$lh+$lz);
				$pdf->MultiCell($colSubCab[0][2],4,$row['tipoingreso'],0,'C');
				
				$ls = $colSubCab[0][0]+$colSubCab[0][1]+$colSubCab[0][2]-5;
				*/
                                /*
                                $pdf->SetFont('arial','',7);
				$pdf->SetXY($lw+$ls,$lh+$lz);
				$pdf->MultiCell($colCab[1]+$colCab[2],4,utf8_decode(substr($row['descripcion'],0,170)),0,'J');
				
				*/
				
				
				$pdf->SetFont('arial','',8);
				$ls = $colSubCab[0][0]+$colSubCab[0][1]+$colSubCab[0][2]+$colCab[1]+$colCab[2]-5;
				
				//$saldo = floatval($row['ntotals']) - $abono;
                                $total = floatval($row['monto']);
                               
                                if($row['mora']>'0' and $row['tipoingreso']<>'0000001255' ){
                                   $total = $total-floatval($row['mora']); //-floatval($row['ged']);
                                }
                                
                                if($row['tipoingreso']<>'0000001261' and $row['ged']>'0'){
                                  $total = $total-floatval($row['ged']);  
                                }
                                
                                    
                                
				/*$pdf->SetXY($lw+$ls,$lh+$lz);
				$pdf->MultiCell($colCab[3],4,number_format($total,2,',',' '),0,'R');
				
				$var1 = $pdf->GetY();
				if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar;*/
			
			
				$sumTotalPartida += $total;
			      
			$Rs_grabar->pg_Move_Next();
                        
			$row2= $Rs_grabar->pg_Get_Row();
			if($row2['cod_par']<>$codPar  or $N == ( $numRows -1 ) ){
				//Sub Total Por Año
				//$lh += 3;
                               // $lz += 6;
				$ls=-5;   
                                $pdf->SetFont('arial','B',10);
				$pdf->SetXY($lw+$ls,$lh+$lz);
                                //$pdf->Line($lw+$ls, $lh+4, 205, $lh +4, $style);
                                
				
                                //$pdf->Line($lw+$ls, $lh+$ls, 210, $lh +$ls, $style);
                                
				
				$pdf->MultiCell($colSubCab[0][0]+$colSubCab[0][1],4,$row['cod_par'],1,'J');
				$pdf->SetXY($lw+$ls+$colSubCab[0][0]+$colSubCab[0][1],$lh+$lz);
				$pdf->MultiCell($colSubCab[0][2],4,$row['cod_fte'],1,'C');
				 $pdf->SetFont('arial','',10);
				$ls = $colSubCab[0][0]+$colSubCab[0][1]+$colSubCab[0][2]-5;
				
				$pdf->SetXY($lw+$ls,$lh+$lz);
				$pdf->MultiCell($colCab[1]+$colCab[2],4, substr( trim($row['nom_sespe_clas']),0,100),1,'J');
				
				$ls = $colSubCab[0][0]+$colSubCab[0][1]+$colSubCab[0][2]+$colCab[1]+$colCab[2]-5;
				
				
				$pdf->SetXY($lw+$ls,$lh+$lz);
				$pdf->MultiCell($colCab[3],4,number_format($sumTotalPartida,2,',',' '),1,'R');
				
				$var1 = $pdf->GetY();
				if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar;
                                
                                
                                switch(trim($row['cod_fte'])){
                                    case '08':
                                        $sumFte08 += $sumTotalPartida;
                                        break;
                                    case '09':
                                        $sumFte09 += $sumTotalPartida;
                                        break;
                                }
                                
                                
                                $sumaTotal += $sumTotalPartida;
                                $sumTotalPartida = 0;
                                
                                $lh += $lz+4;
				
                        }
			
                        //$lh += $lz+4;
                        $lz =0;
			
			
			
			$N++;
		}
		
            //Sub Total Por Año
            //$lh += 3;
                /*$var1 = $pdf->GetY();
                if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar;*/
                $lz += 6;
                $ls=-5;   
                $pdf->SetFont('arial','B',10);
                $pdf->SetXY($lw+$ls,$lh+$lz);
                //$pdf->Line($lw+$ls, $lh+4, 205, $lh +4, $style);


                //$pdf->Line($lw+$ls, $lh+$ls, 210, $lh +$ls, $style);


                $pdf->MultiCell($colSubCab[0][0]+$colSubCab[0][1],4,'',0,'J');
                $pdf->SetXY($lw+$ls+$colSubCab[0][0]+$colSubCab[0][1],$lh+$lz);
                $pdf->MultiCell($colSubCab[0][2],4,'',0,'C');

                $ls = $colSubCab[0][0]+$colSubCab[0][1]+$colSubCab[0][2]-5;

                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colCab[1]+$colCab[2],4,"TOTAL",0,'J');

                $ls = $colSubCab[0][0]+$colSubCab[0][1]+$colSubCab[0][2]+$colCab[1]+$colCab[2]-5;


                $pdf->SetXY($lw+$ls,$lh+$lz);
                $pdf->MultiCell($colCab[3],4,number_format($sumaTotal,2,',',' '),1,'R');

                $var1 = $pdf->GetY();
                if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar;		
		
  $corte = $pdf->WriteResumen($ls,$lh+10, 1);

$pdf->Output();


?>